Trò chơi Tic-Tac-Toe, game đánh caro full source code
53.553 lượt xem;
- PhotonGUI.cs
- PhotonNetwork /
- Editor /
- Photon Unity Networking /
- Assets /
- project /
1 using UnityEngine;
2 using UnityEditor;
3 using System.Collections;
4 using Rotorz.ReorderableList.Internal;
5
6 public class PhotonGUI
7 {
8 #region Styles
9 static GUIStyle m_DefaultTitleStyle;
10 public static GUIStyle DefaultTitleStyle
11 {
12 get
13 {
14 if( m_DefaultTitleStyle == null )
15 {
16 m_DefaultTitleStyle = new GUIStyle();
17 m_DefaultTitleStyle.border = new RectOffset( 2, 2, 2, 1 );
18 m_DefaultTitleStyle.margin = new RectOffset( 5, 5, 5, 0 );
19 m_DefaultTitleStyle.padding = new RectOffset( 5, 5, 0, 0 );
20 m_DefaultTitleStyle.alignment = TextAnchor.MiddleLeft;
21 m_DefaultTitleStyle.normal.background = ReorderableListResources.texTitleBackground;
22 m_DefaultTitleStyle.normal.textColor = EditorGUIUtility.isProSkin
23 ? new Color( 0.8f, 0.8f, 0.8f )
24 : new Color( 0.2f, 0.2f, 0.2f );
25 }
26
27 return m_DefaultTitleStyle;
28 }
29 }
30
31 static GUIStyle m_DefaultContainerStyle;
32 public static GUIStyle DefaultContainerStyle
33 {
34 get
35 {
36 if( m_DefaultContainerStyle == null )
37 {
38 m_DefaultContainerStyle = new GUIStyle();
39 m_DefaultContainerStyle.border = new RectOffset( 2, 2, 1, 2 );
40 m_DefaultContainerStyle.margin = new RectOffset( 5, 5, 5, 5 );
41 m_DefaultContainerStyle.padding = new RectOffset( 1, 1, 2, 2 );
42 m_DefaultContainerStyle.normal.background = ReorderableListResources.texContainerBackground;
43 }
44
45 return m_DefaultContainerStyle;
46 }
47 }
48
49 static GUIStyle m_DefaultAddButtonStyle;
50 public static GUIStyle DefaultAddButtonStyle
51 {
52 get
53 {
54 if( m_DefaultAddButtonStyle == null )
55 {
56 m_DefaultAddButtonStyle = new GUIStyle();
57 m_DefaultAddButtonStyle.fixedWidth = 30;
58 m_DefaultAddButtonStyle.fixedHeight = 16;
59 m_DefaultAddButtonStyle.normal.background = ReorderableListResources.texAddButton;
60 m_DefaultAddButtonStyle.active.background = ReorderableListResources.texAddButtonActive;
61 }
62
63 return m_DefaultAddButtonStyle;
64 }
65 }
66
67 static GUIStyle m_DefaultRemoveButtonStyle;
68 public static GUIStyle DefaultRemoveButtonStyle
69 {
70 get
71 {
72 if( m_DefaultRemoveButtonStyle == null )
73 {
74 m_DefaultRemoveButtonStyle = new GUIStyle();
75 m_DefaultRemoveButtonStyle.fixedWidth = 30;
76 m_DefaultRemoveButtonStyle.fixedHeight = 20;
77 m_DefaultRemoveButtonStyle.active.background = ReorderableListResources.CreatePixelTexture( "Dark Pixel (List GUI)", new Color32( 18, 18, 18, 255 ) );
78 m_DefaultRemoveButtonStyle.imagePosition = ImagePosition.ImageOnly;
79 m_DefaultRemoveButtonStyle.alignment = TextAnchor.MiddleCenter;
80 }
81
82 return m_DefaultRemoveButtonStyle;
83 }
84 }
85
86 static GUIStyle m_DefaultContainerRowStyle;
87 public static GUIStyle DefaultContainerRowStyle
88 {
89 get
90 {
91 if( m_DefaultContainerRowStyle == null )
92 {
93 m_DefaultContainerRowStyle = new GUIStyle();
94 m_DefaultContainerRowStyle.border = new RectOffset( 2, 2, 2, 2 );
95
96 m_DefaultContainerRowStyle.margin = new RectOffset( 5, 5, 5, 5 );
97 m_DefaultContainerRowStyle.padding = new RectOffset( 1, 1, 2, 2 );
98 m_DefaultContainerRowStyle.normal.background = ReorderableListResources.texContainerBackground;
99 }
100
101 return m_DefaultContainerRowStyle;
102 }
103 }
104
105 static GUIStyle m_FoldoutBold;
106 public static GUIStyle FoldoutBold
107 {
108 get
109 {
110 if( m_FoldoutBold == null )
111 {
112 m_FoldoutBold = new GUIStyle( EditorStyles.foldout );
113 m_FoldoutBold.fontStyle = FontStyle.Bold;
114 }
115
116 return m_FoldoutBold;
117 }
118 }
119
120 static GUIStyle m_RichLabel;
121 public static GUIStyle RichLabel
122 {
123 get
124 {
125 if( m_RichLabel == null )
126 {
127 m_RichLabel = new GUIStyle( GUI.skin.label );
128 m_RichLabel.richText = true;
129 m_RichLabel.wordWrap = true;
130 }
131
132 return m_RichLabel;
133 }
134 }
135 #endregion
136
137 static Texture2D m_HelpIcon;
138 public static Texture2D HelpIcon
139 {
140 get
141 {
142 if( m_HelpIcon == null )
143 {
144 m_HelpIcon = AssetDatabase.LoadAssetAtPath( "Assets/Photon Unity Networking/Editor/PhotonNetwork/help.png", typeof( Texture2D ) ) as Texture2D;
145 }
146
147 return m_HelpIcon;
148 }
149 }
150
151 #region Interface
152 public static void ContainerHeader( string headline )
153 {
154 DoContainerHeader( headline, 27, 0 );
155 }
156
157 public static bool ContainerHeaderToggle( string headline, bool toggle )
158 {
159 return DoContainerHeaderToggle( headline, toggle );
160 }
161
162 public static bool ContainerHeaderFoldout( string headline, bool foldout )
163 {
164 return DoContainerHeaderFoldout( headline, foldout );
165 }
166
167 public static Rect ContainerBody( float height )
168 {
169 return DoContainerBody( height );
170 }
171
172 public static bool AddButton()
173 {
174 Rect controlRect = EditorGUILayout.GetControlRect( false, DefaultAddButtonStyle.fixedHeight - 5 );
175 controlRect.yMin -= 5;
176 controlRect.yMax -= 5;
177
178 Rect addButtonRect = new Rect( controlRect.xMax - DefaultAddButtonStyle.fixedWidth,
179 controlRect.yMin,
180 DefaultAddButtonStyle.fixedWidth,
181 DefaultAddButtonStyle.fixedHeight );
182
183 return GUI.Button( addButtonRect, "", DefaultAddButtonStyle );
184 }
185
186 public static void DrawSplitter( Rect position )
187 {
188 ReorderableListResources.DrawTexture( position, ReorderableListResources.texItemSplitter );
189 }
190
191 public static void DrawGizmoOptions(
192 Rect position,
193 string label,
194 SerializedProperty gizmoEnabledProperty,
195 SerializedProperty gizmoColorProperty,
196 SerializedProperty gizmoTypeProperty,
197 SerializedProperty gizmoSizeProperty )
198 {
199 float height = EditorGUIUtility.singleLineHeight;
200 float flexibleWidth = Mathf.Max( 40, position.width - EditorGUIUtility.labelWidth - 20 - 75 - 5 - 40 - 5 );
201
202 Rect labelRect = new Rect( position.xMin, position.yMin, EditorGUIUtility.labelWidth, height );
203 GUI.Label( labelRect, label );
204
205 Rect enabledRect = new Rect( labelRect.xMax, labelRect.yMin, 20, height );
206 EditorGUI.PropertyField( enabledRect, gizmoEnabledProperty, GUIContent.none );
207
208 bool oldGUIEnabled = GUI.enabled;
209 GUI.enabled = gizmoEnabledProperty.boolValue;
210
211 Rect colorRect = new Rect( enabledRect.xMax + 5, labelRect.yMin, 70, height );
212 EditorGUI.PropertyField( colorRect, gizmoColorProperty, GUIContent.none );
213
214 Rect typeRect = new Rect( colorRect.xMax + 5, labelRect.yMin, flexibleWidth * 0.7f, height );
215 EditorGUI.PropertyField( typeRect, gizmoTypeProperty, GUIContent.none );
216
217 Rect sizeLabelRect = new Rect( typeRect.xMax + 10, labelRect.yMin, 30, height );
218 GUI.Label( sizeLabelRect, "Size" );
219
220 Rect sizeRect = new Rect( sizeLabelRect.xMax + 5, labelRect.yMin, flexibleWidth * 0.3f, height );
221 EditorGUI.PropertyField( sizeRect, gizmoSizeProperty, GUIContent.none );
222
223 GUI.enabled = oldGUIEnabled;
224 }
225
226 #endregion
227
228 #region Implementation
229 static Rect DoContainerBody( float height )
230 {
231 Rect controlRect = EditorGUILayout.GetControlRect( false, height );
232 controlRect.yMin -= 3;
233 controlRect.yMax -= 2;
234
235 int controlID = GUIUtility.GetControlID( FocusType.Passive, controlRect );
236
237 if( Event.current.type == EventType.Repaint )
238 {
239 PhotonGUI.DefaultContainerStyle.Draw( controlRect, GUIContent.none, controlID );
240 }
241
242 return controlRect;
243 }
244
245 static bool DoContainerHeaderToggle( string headline, bool toggle )
246 {
247 Rect rect = DoContainerHeader( headline, 27, 15 );
248 Rect toggleRect = new Rect( rect.xMin + 5, rect.yMin + 5, EditorGUIUtility.labelWidth, rect.height );
249
250 return EditorGUI.Toggle( toggleRect, toggle );
251 }
252
253
254 static bool DoContainerHeaderFoldout( string headline, bool foldout )
255 {
256 Rect rect = DoContainerHeader( "", 27, 0f );
257 Rect foldoutRect = new Rect( rect.xMin + 15, rect.yMin + 5, rect.width, rect.height );
258
259 return EditorGUI.Foldout( foldoutRect, foldout, headline, FoldoutBold );
260 }
261
262 static Rect DoContainerHeader( string headline, float height, float contentOffset )
263 {
264 GUILayout.Space( 5 );
265 Rect controlRect = EditorGUILayout.GetControlRect( false, height );
266
267 int controlID = GUIUtility.GetControlID( FocusType.Passive, controlRect );
268
269 if( Event.current.type == EventType.Repaint )
270 {
271 PhotonGUI.DefaultTitleStyle.Draw( controlRect, GUIContent.none, controlID );
272
273 Rect labelRect = new Rect( controlRect.xMin + 5 + contentOffset, controlRect.yMin + 5, controlRect.width, controlRect.height );
274 GUI.Label( labelRect, headline, EditorStyles.boldLabel );
275 }
276
277 return controlRect;
278 }
279 #endregion
280 }
2 using UnityEditor;
3 using System.Collections;
4 using Rotorz.ReorderableList.Internal;
5
6 public class PhotonGUI
7 {
8 #region Styles
9 static GUIStyle m_DefaultTitleStyle;
10 public static GUIStyle DefaultTitleStyle
11 {
12 get
13 {
14 if( m_DefaultTitleStyle == null )
15 {
16 m_DefaultTitleStyle = new GUIStyle();
17 m_DefaultTitleStyle.border = new RectOffset( 2, 2, 2, 1 );
18 m_DefaultTitleStyle.margin = new RectOffset( 5, 5, 5, 0 );
19 m_DefaultTitleStyle.padding = new RectOffset( 5, 5, 0, 0 );
20 m_DefaultTitleStyle.alignment = TextAnchor.MiddleLeft;
21 m_DefaultTitleStyle.normal.background = ReorderableListResources.texTitleBackground;
22 m_DefaultTitleStyle.normal.textColor = EditorGUIUtility.isProSkin
23 ? new Color( 0.8f, 0.8f, 0.8f )
24 : new Color( 0.2f, 0.2f, 0.2f );
25 }
26
27 return m_DefaultTitleStyle;
28 }
29 }
30
31 static GUIStyle m_DefaultContainerStyle;
32 public static GUIStyle DefaultContainerStyle
33 {
34 get
35 {
36 if( m_DefaultContainerStyle == null )
37 {
38 m_DefaultContainerStyle = new GUIStyle();
39 m_DefaultContainerStyle.border = new RectOffset( 2, 2, 1, 2 );
40 m_DefaultContainerStyle.margin = new RectOffset( 5, 5, 5, 5 );
41 m_DefaultContainerStyle.padding = new RectOffset( 1, 1, 2, 2 );
42 m_DefaultContainerStyle.normal.background = ReorderableListResources.texContainerBackground;
43 }
44
45 return m_DefaultContainerStyle;
46 }
47 }
48
49 static GUIStyle m_DefaultAddButtonStyle;
50 public static GUIStyle DefaultAddButtonStyle
51 {
52 get
53 {
54 if( m_DefaultAddButtonStyle == null )
55 {
56 m_DefaultAddButtonStyle = new GUIStyle();
57 m_DefaultAddButtonStyle.fixedWidth = 30;
58 m_DefaultAddButtonStyle.fixedHeight = 16;
59 m_DefaultAddButtonStyle.normal.background = ReorderableListResources.texAddButton;
60 m_DefaultAddButtonStyle.active.background = ReorderableListResources.texAddButtonActive;
61 }
62
63 return m_DefaultAddButtonStyle;
64 }
65 }
66
67 static GUIStyle m_DefaultRemoveButtonStyle;
68 public static GUIStyle DefaultRemoveButtonStyle
69 {
70 get
71 {
72 if( m_DefaultRemoveButtonStyle == null )
73 {
74 m_DefaultRemoveButtonStyle = new GUIStyle();
75 m_DefaultRemoveButtonStyle.fixedWidth = 30;
76 m_DefaultRemoveButtonStyle.fixedHeight = 20;
77 m_DefaultRemoveButtonStyle.active.background = ReorderableListResources.CreatePixelTexture( "Dark Pixel (List GUI)", new Color32( 18, 18, 18, 255 ) );
78 m_DefaultRemoveButtonStyle.imagePosition = ImagePosition.ImageOnly;
79 m_DefaultRemoveButtonStyle.alignment = TextAnchor.MiddleCenter;
80 }
81
82 return m_DefaultRemoveButtonStyle;
83 }
84 }
85
86 static GUIStyle m_DefaultContainerRowStyle;
87 public static GUIStyle DefaultContainerRowStyle
88 {
89 get
90 {
91 if( m_DefaultContainerRowStyle == null )
92 {
93 m_DefaultContainerRowStyle = new GUIStyle();
94 m_DefaultContainerRowStyle.border = new RectOffset( 2, 2, 2, 2 );
95
96 m_DefaultContainerRowStyle.margin = new RectOffset( 5, 5, 5, 5 );
97 m_DefaultContainerRowStyle.padding = new RectOffset( 1, 1, 2, 2 );
98 m_DefaultContainerRowStyle.normal.background = ReorderableListResources.texContainerBackground;
99 }
100
101 return m_DefaultContainerRowStyle;
102 }
103 }
104
105 static GUIStyle m_FoldoutBold;
106 public static GUIStyle FoldoutBold
107 {
108 get
109 {
110 if( m_FoldoutBold == null )
111 {
112 m_FoldoutBold = new GUIStyle( EditorStyles.foldout );
113 m_FoldoutBold.fontStyle = FontStyle.Bold;
114 }
115
116 return m_FoldoutBold;
117 }
118 }
119
120 static GUIStyle m_RichLabel;
121 public static GUIStyle RichLabel
122 {
123 get
124 {
125 if( m_RichLabel == null )
126 {
127 m_RichLabel = new GUIStyle( GUI.skin.label );
128 m_RichLabel.richText = true;
129 m_RichLabel.wordWrap = true;
130 }
131
132 return m_RichLabel;
133 }
134 }
135 #endregion
136
137 static Texture2D m_HelpIcon;
138 public static Texture2D HelpIcon
139 {
140 get
141 {
142 if( m_HelpIcon == null )
143 {
144 m_HelpIcon = AssetDatabase.LoadAssetAtPath( "Assets/Photon Unity Networking/Editor/PhotonNetwork/help.png", typeof( Texture2D ) ) as Texture2D;
145 }
146
147 return m_HelpIcon;
148 }
149 }
150
151 #region Interface
152 public static void ContainerHeader( string headline )
153 {
154 DoContainerHeader( headline, 27, 0 );
155 }
156
157 public static bool ContainerHeaderToggle( string headline, bool toggle )
158 {
159 return DoContainerHeaderToggle( headline, toggle );
160 }
161
162 public static bool ContainerHeaderFoldout( string headline, bool foldout )
163 {
164 return DoContainerHeaderFoldout( headline, foldout );
165 }
166
167 public static Rect ContainerBody( float height )
168 {
169 return DoContainerBody( height );
170 }
171
172 public static bool AddButton()
173 {
174 Rect controlRect = EditorGUILayout.GetControlRect( false, DefaultAddButtonStyle.fixedHeight - 5 );
175 controlRect.yMin -= 5;
176 controlRect.yMax -= 5;
177
178 Rect addButtonRect = new Rect( controlRect.xMax - DefaultAddButtonStyle.fixedWidth,
179 controlRect.yMin,
180 DefaultAddButtonStyle.fixedWidth,
181 DefaultAddButtonStyle.fixedHeight );
182
183 return GUI.Button( addButtonRect, "", DefaultAddButtonStyle );
184 }
185
186 public static void DrawSplitter( Rect position )
187 {
188 ReorderableListResources.DrawTexture( position, ReorderableListResources.texItemSplitter );
189 }
190
191 public static void DrawGizmoOptions(
192 Rect position,
193 string label,
194 SerializedProperty gizmoEnabledProperty,
195 SerializedProperty gizmoColorProperty,
196 SerializedProperty gizmoTypeProperty,
197 SerializedProperty gizmoSizeProperty )
198 {
199 float height = EditorGUIUtility.singleLineHeight;
200 float flexibleWidth = Mathf.Max( 40, position.width - EditorGUIUtility.labelWidth - 20 - 75 - 5 - 40 - 5 );
201
202 Rect labelRect = new Rect( position.xMin, position.yMin, EditorGUIUtility.labelWidth, height );
203 GUI.Label( labelRect, label );
204
205 Rect enabledRect = new Rect( labelRect.xMax, labelRect.yMin, 20, height );
206 EditorGUI.PropertyField( enabledRect, gizmoEnabledProperty, GUIContent.none );
207
208 bool oldGUIEnabled = GUI.enabled;
209 GUI.enabled = gizmoEnabledProperty.boolValue;
210
211 Rect colorRect = new Rect( enabledRect.xMax + 5, labelRect.yMin, 70, height );
212 EditorGUI.PropertyField( colorRect, gizmoColorProperty, GUIContent.none );
213
214 Rect typeRect = new Rect( colorRect.xMax + 5, labelRect.yMin, flexibleWidth * 0.7f, height );
215 EditorGUI.PropertyField( typeRect, gizmoTypeProperty, GUIContent.none );
216
217 Rect sizeLabelRect = new Rect( typeRect.xMax + 10, labelRect.yMin, 30, height );
218 GUI.Label( sizeLabelRect, "Size" );
219
220 Rect sizeRect = new Rect( sizeLabelRect.xMax + 5, labelRect.yMin, flexibleWidth * 0.3f, height );
221 EditorGUI.PropertyField( sizeRect, gizmoSizeProperty, GUIContent.none );
222
223 GUI.enabled = oldGUIEnabled;
224 }
225
226 #endregion
227
228 #region Implementation
229 static Rect DoContainerBody( float height )
230 {
231 Rect controlRect = EditorGUILayout.GetControlRect( false, height );
232 controlRect.yMin -= 3;
233 controlRect.yMax -= 2;
234
235 int controlID = GUIUtility.GetControlID( FocusType.Passive, controlRect );
236
237 if( Event.current.type == EventType.Repaint )
238 {
239 PhotonGUI.DefaultContainerStyle.Draw( controlRect, GUIContent.none, controlID );
240 }
241
242 return controlRect;
243 }
244
245 static bool DoContainerHeaderToggle( string headline, bool toggle )
246 {
247 Rect rect = DoContainerHeader( headline, 27, 15 );
248 Rect toggleRect = new Rect( rect.xMin + 5, rect.yMin + 5, EditorGUIUtility.labelWidth, rect.height );
249
250 return EditorGUI.Toggle( toggleRect, toggle );
251 }
252
253
254 static bool DoContainerHeaderFoldout( string headline, bool foldout )
255 {
256 Rect rect = DoContainerHeader( "", 27, 0f );
257 Rect foldoutRect = new Rect( rect.xMin + 15, rect.yMin + 5, rect.width, rect.height );
258
259 return EditorGUI.Foldout( foldoutRect, foldout, headline, FoldoutBold );
260 }
261
262 static Rect DoContainerHeader( string headline, float height, float contentOffset )
263 {
264 GUILayout.Space( 5 );
265 Rect controlRect = EditorGUILayout.GetControlRect( false, height );
266
267 int controlID = GUIUtility.GetControlID( FocusType.Passive, controlRect );
268
269 if( Event.current.type == EventType.Repaint )
270 {
271 PhotonGUI.DefaultTitleStyle.Draw( controlRect, GUIContent.none, controlID );
272
273 Rect labelRect = new Rect( controlRect.xMin + 5 + contentOffset, controlRect.yMin + 5, controlRect.width, controlRect.height );
274 GUI.Label( labelRect, headline, EditorStyles.boldLabel );
275 }
276
277 return controlRect;
278 }
279 #endregion
280 }